home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 564 < prev    next >
Encoding:
Text File  |  1996-08-05  |  7.0 KB  |  175 lines

  1. Path: cs.uwa.edu.au!jasonb
  2. From: jasonb@cs.uwa.edu.au (Jason S Birch)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: PPC compilers
  5. Date: 9 Jan 96 08:23:44 GMT
  6. Organization: The University of Western Australia
  7. Message-ID: <jasonb.821175824@cs.uwa.edu.au>
  8. References: <john.hendrikx.40ka@grafix.xs4all.nl> <4b77tq$htp@serpens.rhein.de> <MQAQx*XOe@yaps.rhein.de> <4bqhnf$6g5@sunsystem5.informatik.tu-muenchen.de> <jasonb.820051107@cs.uwa.edu.au> <4c9i2l$h3i@sunsystem5.informatik.tu-muenchen.de> <4cf0ep$233@ra.i   <4ck47h$g07@maureen.teleport.com> <jasonb.820919731@cs.uwa.edu.au> <4com6v$415@maureen.teleport.com> <jasonb.821098303@cs.uwa.edu.au> <4crfb9$djs@maureen.teleport.com>
  9. NNTP-Posting-Host: decadence.cs.uwa.oz.au
  10. X-Newsreader: NN version 6.5.0 #3 (NOV)
  11.  
  12. sschaem@teleport.com (Stephan Schaem) writes:
  13. >Jason S Birch (jasonb@cs.uwa.edu.au) wrote:
  14. >: Again: *If* he's trying to create a data type with certain
  15. >: implementation-dependent size-requirements (such as in the bltcon0
  16. >: case, assuming no headers to give us one) *then*, at that point in
  17. >: time, he has to know the size of the type in order to define it
  18. >: correctly. He stated that earlier - check what I've underlined.
  19.  
  20. > He said he would create a structure... not a new type.
  21.  
  22. You're saying a new structure *isn't* a new type?
  23.  
  24. > Now, tell me how he can forget that chipregs->bltcon0 is
  25. > of type UWORD when he will declar *b and use *b (I guess you
  26. > could forget what type are your variable, but personaly think its
  27. > not to wise) 
  28.  
  29. typedef uword bltcon0_t;
  30. ...
  31. struct chipregs_t {
  32.     ...
  33.     bltcon0_t    bltcon0;
  34.     ...
  35. };
  36.  
  37. struct chipregs_t    chipregs;
  38. bltcon0_t            *b;
  39.  
  40. Now he can safely use *b wherever a bltcon0_t is required, and given
  41. sufficient support functions, never needs to know that it's a uword -
  42. all he has to keep in mind are what values a bltcon0_t is allowed to
  43. take.
  44.  
  45. > I'm sorry again , I dont see how you can program not knowing  
  46. > the type of your variable when you use them? Is it a pointer to a
  47. > string C string? a pointer to a P String? 
  48.  
  49. Again, you're misunderstanding. If you have a type blah, and a
  50. function takes a variable of type blah *, then by all means create a
  51. variable of type blah (or blah *) and pass it's address (or the
  52. variable itself) to the function. You do *not*, however, need to know
  53. if blah is really, say, a 32-bit integer. With assembler, you do.
  54.  
  55. > Should I mask the variable
  56. > before I shift? etc...
  57.  
  58. If you use bitfields, you don't even have to care about masking and
  59. shifting:
  60.  
  61. typedef struct {
  62.   int foo : 2;
  63.   int bar : 4;
  64.   int bob : 10;
  65. } fred_t;
  66.  
  67. main()
  68. {
  69.     fred_t fred;
  70.  
  71.     fred.foo = 3;
  72.     fred.bar = 7;
  73.     fred.bob = 11;
  74.  
  75.     return 0;
  76. }
  77.  
  78. Produces:
  79. __code:
  80. main:
  81.               MOVE.L         A7,D0                    ;200f 
  82.               SUBQ.L         #$4,D0                   ;5980 
  83.               CMP.L          __base(A4),D0            ;b0ac 0000 
  84.               BCS.W          _XCOVF                   ;6500 0000 
  85.               SUBQ.W         #$4,A7                   ;594f 
  86. ___main__1:
  87.               MOVEQ.L        #$3,D0                   ;7003 
  88.               BFINS          D0,$2(A7){0:2}           ;efef 0002 0002
  89.               MOVEQ.L        #$7,D0                   ;7007 
  90.               BFINS          D0,$2(A7){2:4}           ;efef 0084 0002
  91.               MOVEQ.L        #$b,D0                   ;700b 
  92.               BFINS          D0,$2(A7){6:10}          ;efef 018a 0002
  93.               MOVEQ.L        #$0,D0                   ;7000 
  94. ___main__2:
  95. ___main__3:
  96.               ADDQ.W         #$4,A7                   ;584f 
  97.               RTS                                     ;4e75 
  98.  
  99. fred_t can be your interface to some custom chip; foo, bar, and bob
  100. can be "registers" you can use for whatever is required. The
  101. definitions tell you exactly how many bits each can take, and that's
  102. all you need to know. The compiler will take care of the rest.
  103.  
  104. >: However, once done, he can then safely create variables of that type
  105. >: (the abstract one he's defined, which happens to be the right size) and
  106. >: safely assign appropriate values to them, without having to worry if
  107. >: the eventual assignments are implemented as a .c, .w, or .l. He can
  108.  
  109. > He defined a structure not a type... read what you underlined.
  110.  
  111. Structures *are* types. 
  112.  
  113. > move.type    (a0),(a1) ... so what if type read .word or .chipreg
  114.  
  115. The "so what" is that you *need* to know if it really is a type .word,
  116. or .byte, and can't simply use it as type .chipreg. Oh, and you have
  117. to repeatedly say .word (or whatever) almost every time you use it.
  118.  
  119. > In asm you are forced to write what your thinking in all its detail,
  120. > this mean forced to know your variable type. Something you should do
  121. > even in C.
  122.  
  123. Not if you want portable code, you shouldn't, and with sufficient
  124. support functions, you needn't.
  125.  
  126. >: The question is not about whether you need to know if a variable is a
  127. >: float or a long, since they are "abstract" types (and can be different
  128. >: sizes on different machines). The question is whether you need to know
  129. >: how many bits are in each, and what each bit means. In assembler, you
  130. >: do need to know the former, and occasionally the latter.
  131.  
  132. > When you program in C... on what basis do you select your variable type?
  133. > Do you limit yourself to int/float? for all integer work you use int, 
  134. > and real you use float?
  135.  
  136. Of course not. If I need a lot of precision, I use double. If I prefer
  137. speed and it doesn't need to be so accurate, I use float. If it
  138. doesn't need to be floating point at all, I'll use an ordinal type. If
  139. I don't want to have to care how big it's going to be on a particular
  140. implementation, I'll go with long or perhaps "natural", where natural
  141. can be typedef'd appropriately when sizeof(word) and sizeof(long) are
  142. known. You are quite welcome, as I've said, to use the knowledge that
  143. ANSI guarantees. If you want to be safe, however, you should not use
  144. information that your particular implementation defines.
  145.  
  146. > In C or asm I choose type according the the min range they hold.
  147. > I cant imagine choosing a type for my operation without knowing the
  148. > type range.
  149.  
  150. You can't know the type range beforehand for any possible
  151. implementation. C does not guarantee it. You can use sizeof at compile
  152. time, however.
  153.  
  154. >: > ANSI define very well the minimum size of its type.
  155.  
  156. >: It does *not* define that ushort is the same as two bytes, which is
  157. >: what you are claiming above as being equivalent. It only guarantees
  158. >: that char <= short <= long.
  159.  
  160. > It define that ushort can hold value from 0 to 65535... this is what I
  161. > claim. ANSI C do define min range for the basic types, it would be
  162. > unthinkable otherwise.
  163.  
  164. It does *not* define that ushort can hold values from 0 to 65535.
  165. Check it. There are machines with other than multiples of 8 bit word
  166. sizes, you know.
  167.  
  168. > Stephan
  169.  
  170. -- 
  171. Jason S Birch                        ,-_|\ email: jasonb@cs.uwa.edu.au
  172. Department of Computer Science      /     \ Tel (work): +61 9 380 1840
  173. The University of Western Australia *_.-._/ Fax (work): +61 9 380 1089
  174. Nedlands  W. Australia  6907             v  Tel (home): +61 9 386 8630
  175.